Ext.namespace("Task.Back");

Task.Back.win = function() {
	this.users = [];
	this.userSelector = null;
	this.selectUserId = [];
	this.loadMask = null;
	this.taskExeId;
	this.taskId;
	this.from;
	this.to;
	
	this.txtTitle = new Ext.form.TextField({
        fieldLabel: '任务名称',
        width: 300,
        readOnly:true,
        blankText: '请输入任务名称!'
    });
	this.txtExecutor = new Ext.form.TextField({
		fieldLabel: '执行人',
		disabled: true,
		width: 190//,
		//blankText: '请选择执行人'//,
//		listeners: {
//		   'render': function(cmp) {
//				var self = cmp.ownerCt.ownerCt.ownerCt;
//				cmp.getEl().on('click', self.showSelector, self); 
//			}
//		}
	});
	this.txtTaskOrigin = new Ext.form.ComboBox({
		width: 100,
		fieldLabel: '任务来源',
        store: new Ext.data.ArrayStore({
        	fields: ['value', 'name'],
        		data: OMS.TASKORIGINVALUE
        }),
        value: 0,
        valueField: 'value',
        displayField: 'name',
        editable: false,
        disabled:true,
        mode: 'local',
        triggerAction: 'all',
        selectOnFocus: true
	});
	
	this.txtContent = new Ext.form.HtmlEditor({
		fieldLabel: '任务内容',
		width:400,
		height:200,
		designMode:'off',//Modified by wilson
		autoScroll:true
	});
	this.dtFeedback = new Ext.ux.form.DateTime({
		fieldLabel: '反馈时间',
		timeFormat:'H:i',
        timeConfig: {
             altFormats:'H:i',
            allowBlank: true,
              disabled:true   
        },
        dateFormat:'Y-m-d',
        dateConfig: {
            altFormats:'Y-m-d',
            allowBlank: false,   
              disabled:true 
       }
	});
	this.chkRemind = new Ext.form.CheckboxGroup({
		width:110,
		fieldLabel: '提醒设置',
		items: [
		        {boxLabel: '短信', name: 'smsRemind'},
		        {boxLabel: '邮件', name: 'emailRemind'}
		]
	});
	this.feedBackContent = new Ext.form.TextArea({
		fieldLabel:'退回原因',
		width:350,
		 allowBlank: false,
		height:30,
		maxLength:200
	});
	this.form = new Ext.FormPanel({
        bodyStyle: 'padding: 5px 5px 0',
        labelWidth: 75,
        frame:true,
        labelAlign: 'right',
        width: 520,
        items: [this.txtTitle, this.txtContent, {
        	layout: 'column',
        	defaults: {layout: 'form'},
        	items: [ {
        			columnWidth: .6,
        			items: [this.txtExecutor, this.dtFeedback]
        		},{
        			columnWidth: .4,
        			items: [this.txtTaskOrigin, this.chkRemind]
        		}
        	]
        }, this.feedBackContent]
//       	layout:'table',
//       	layoutConfig:{columns:2},
//        items: [
//         {colspan:2,layout:'form',items:[this.txtTitle]},
//         {colspan:2,layout:'form',items:[this.txtContent]},
//         {colspan:1,layout:'form',items:[this.txtExecutor]},
//         {colspan:1,layout:'form',items:[this.txtTaskOrigin]},
//         {colspan:1,layout:'form',items:[this.dtFeedback]},
//         {colspan:1,layout:'form',items:[this.chkRemind]},
//         {colspan:2,layout:'form',items:[this.feedBackContent]}
//		]
    });
	this.backCon = new Ext.data.Connection({
		url:'../task/uptTaskExeStatus.form?timesnap=' + Date.parse(new Date()),
		method:'post'
	});
	this.btnBack = new Ext.Button({
		 text:'退回',
      //   cls: 'x-btn-text-icon btn-save',
         handler: this.back,
         scope: this
	});
	this.btnAgree = new Ext.Button({
		 text:'接受',
        // cls: 'x-btn-text-icon btn-save',
         handler: this.save,
         scope: this
	});
	
	Task.Back.win.superclass.constructor.call(this, {
		title: '任务退回',
        bodyStyle: 'padding: 5px 5px 0',
        autoHeight: true,
        width: 550,
        resizable: false,
        plain: true,
        modal: true,
        autoScroll: true,
        closeAction: 'hide',
        items: [this.form],
        buttons: [this.btnBack,this.btnAgree],
        buttonAlign:'center'
	});
};
Ext.extend(Task.Back.win, Ext.Window, {
	initBack:function(data){
		this.form.getForm().reset();
		this.taskExeId = data.TASK_EXE_ID;
		this.txtTitle.setValue(data.TASK_TITLE);
		this.txtContent.setValue(data.TASK_CONTENT);
		this.dtFeedback.setValue(data.TASK_COMPLETE_DATE);
		//this.txtExecutor.setValue(data.TASK_EXECUTOR);	// Modified By Greco 2010-1-11 15:51
		this.txtExecutor.setValue(data.USER_NAME);
		this.txtTaskOrigin.setValue(data.TASK_ORIGIN);
		this.taskId= data.TASK_ID;
		this.from = data.TASK_EXE_USER_ID;
		this.to = data.TASK_EXE_DISPATCHER_ID,
		this.btnBack.show();
		this.btnAgree.hide();
		// Modified by Greco 2010-1-11 15:51
//		var conn = new Ext.data.Connection({
//			url:'../task/searchTaskExes.form?timesnap=' + Date.parse(new Date()),
//			method:'post'
//		});
//		Utils.request(conn,{
//			params:{
//				taskId:this.taskId
//			},
//			scope:this,
//			success:function(data){
//				var userNames = [];
//				for(var i =0;i<data.exes.length;i++){
//					userNames.push(data.exes[i].USER_NAME);
//				}
//				this.scope.txtExecutor.setValue(userNames.join(';'));
//			}
//		})
	},
	initDetail:function(){
		this.form.getForm().reset();
		this.taskExeId = data.TASK_EXE_ID;
		this.txtTitle.setValue(data.TASK_TITLE);
		this.txtContent.setValue(data.TASK_CONTENT);
		this.dtFeedback.setValue(data.TASK_COMPLETE_DATE);
		this.txtExecutor.setValue(data.TASK_EXECUTOR);
		this.btnBack.show();
		this.btnAgree.show();
	},
	back: function(btn, event) {
		if(!this.form.getForm().isValid()){
			Utils.info("有必填项没有填写，请检查！","系统提示");
			return;
		}
		if (!this.loadMask) {
			 this.loadMask = new Ext.LoadMask(this.form.getEl(), {msg: '派发中，请稍候...'});
		}
		var date = this.dtFeedback.getValue();
		Utils.request(this.backCon,{
			scope:this,
			params:{title:this.txtTitle.getValue(),
				from:this.from,
				to:this.to,
				taskId: this.taskId,
				exeId:this.taskExeId,
				status:'2',
				remark:this.feedBackContent.getValue()
			},success:function(){
				Utils.info("操作成功");
				Task.Prepare.panel.instance.store.reload();
				this.scope.hide();
				//Plan.Open.panel.instance.store.reload();
			}
		})
	},
	showSelector: function(event) {
		if (!this.userSelector) {
			this.userSelector = new Selector.User(this, '执行人');
		}
		this.userSelector.initUsers(this.users);
		this.userSelector.show();
	},
	setUsers: function(o) {	// for Selector.User callback
		this.users = o;
		var names = [];
		for(var i=0, u; u = this.users[i++];) {
			names.push(u.name);
			this.selectUserId.push(u.id);
		}
		this.txtExecutor.setValue(names.join(';'));
	}
});

